import {
	sqlHelper
} from './sqlHelper'
import {
	tempTable
} from './tempTable'
let tempScanCodeShortData = {};
//短连接


/*
把所有的短连接放进 本地
[{Id: 1,createdate: '2020-01-2',url: 'http://www.baidu.com',lvyan_key: '1',Value:'1'}]
*/
tempScanCodeShortData.AddScanCodeShortData = (data) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShort.TableName, tempTable.ScanCodeShort.Columns);
		}).then(e => {
			return sqlHelper.Insert(tempTable.ScanCodeShort.TableName, data)
		}).then(e => {
			resolve(e)
		})
	})
};
/*
查看所有
*/
tempScanCodeShortData.GetAllScanCodeShortData = () => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShort.TableName, tempTable.ScanCodeShort.Columns);
		}).then(e => {
			return sqlHelper.FindAll(tempTable.ScanCodeShort.TableName)
		}).then(e => {
			resolve(e)
		})
	})
};
/*
通过短连接查看某个连接
*/
tempScanCodeShortData.GetScanCodeShortDataByValue = (value) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShort.TableName, tempTable.ScanCodeShort.Columns);
		}).then(e => {
			return sqlHelper.FindAll(tempTable.ScanCodeShort.TableName)
		}).then(e => {
			var findOne = e.data.find(t => t.value == value)
			resolve(findOne)
		})
	})
};

/*删除所有的*/
tempScanCodeShortData.DeleteScanCodeShortData = () => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShort.TableName, tempTable.ScanCodeShort.Columns);
		}).then(e => {
			return sqlHelper.DeleteAll(tempTable.ScanCodeShort.TableName)
		}).then(e => {
			resolve(e)
		})
	})
};


/*新增照片*/
tempScanCodeShortData.AddScanCodeShortDataDetails = (data) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShortDetails.TableName, tempTable.ScanCodeShortDetails.Columns);
		}).then(e => {
			return sqlHelper.Insert(tempTable.ScanCodeShortDetails.TableName, data)
		}).then(e => {
			resolve(e)
		})
	})
};
/*删除所有的的照片*/
tempScanCodeShortData.DeleteScanCodeShortDataDetails = () => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShortDetails.TableName, tempTable.ScanCodeShortDetails.Columns);
		}).then(e => {
			return sqlHelper.DeleteAll(tempTable.ScanCodeShortDetails.TableName)
		}).then(e => {
			resolve(e)
		})
	})
};
/*更具外键 删除照片*/
tempScanCodeShortData.DeleteScanCodeShortDataDetails_ForeignKey = (ForeignKey) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShortDetails.TableName, tempTable.ScanCodeShortDetails.Columns);
		}).then(e => {
			return sqlHelper.DeleteForeignKey(tempTable.ScanCodeShortDetails.TableName,ForeignKey)
		}).then(e => {
			resolve(e)
		})
	})
};
 /*更具外键 查看照片*/
tempScanCodeShortData.GetScanCodeShortDataBy_ForeignKey = (ForeignKey) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.ScanCodeShortDetails.TableName, tempTable.ScanCodeShortDetails.Columns);
		}).then(e => {
			return sqlHelper.FindForeignKey(tempTable.ScanCodeShortDetails.TableName,ForeignKey)
		}).then(e => {
			resolve(e)
		})
	})
};

module.exports = {
	tempScanCodeShortData
}
